package com.atghost.minio.util;

import javax.validation.constraints.NotBlank;

/**
 * @author zyp
 * @since 2023/7/7 下午3:38
 */
public class FileUrlUtils {
    private static final String FILE_URL_BY_FILE_REF_ID =
            "/condor/fileDload/download?fileRefId=%s";
    private static final String FILE_URL_BY_FILE_INODE_ID =
            "/condor/fileDload/downloadByInodeId?fileInodeId=%s&fileName=%s";

    /**
     * 将文件id转换为url
     */
    public static String getUrlByFileRefId(Long fileRefId) {
        if (fileRefId == null) {
            return null;
        }
        return String.format(FILE_URL_BY_FILE_REF_ID, fileRefId);
    }

    /**
     * 将文件id转换为url
     */
    public static String getUrlByFileRefId(String fileRefId) {
        if (fileRefId == null || fileRefId.isEmpty()) {
            return null;
        }
        return String.format(FILE_URL_BY_FILE_REF_ID, fileRefId);
    }

    /**
     * 将文件inodeid转换为url
     */
    public static String getUrlByFileInodeId(Long fileInodeId, @NotBlank String fileName) {
        if (fileInodeId == null) {
            return null;
        }
        if (fileName == null) {
            fileName = String.valueOf(fileInodeId);
        }
        return String.format(FILE_URL_BY_FILE_INODE_ID, fileInodeId, fileName);
    }

    /**
     * 将文件inodeid转换为url
     */
    public static String getUrlByFileInodeId(String fileInodeId, @NotBlank String fileName) {
        if (fileInodeId == null || fileInodeId.isEmpty()) {
            return null;
        }
        if (fileName == null) {
            fileName = String.valueOf(fileInodeId);
        }
        return String.format(FILE_URL_BY_FILE_INODE_ID, fileInodeId, fileName);
    }
}
